package com.xjj.serviceattend.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xjj.entity.Attend;
import com.xjj.entity.PageBean;
import com.xjj.entity.Student;
import com.xjj.serviceattend.mapper.AttendMapper;
import com.xjj.serviceattend.service.AttendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Auther: AYang
 * @Date: 2022/10/20 10:51
 * @Description:
 */
@Service
// @Transactional
public class AttendServiceImpl extends ServiceImpl<AttendMapper, Attend> implements AttendService {
    @Autowired
    private AttendMapper attendMapper;

    @Override
    public PageBean<Attend> getByPage(Attend attend, Integer pageNum, Integer pageSize) {
        PageBean<Attend> pageBean = new PageBean<>();
        Page page = PageHelper.startPage(pageNum, pageSize);
        List<Attend> goodsList = attendMapper.getByCondition(attend);
        log.debug("goodList:{}" + goodsList);

        pageBean.setCurrPage(pageNum);
        pageBean.setData(goodsList);
        pageBean.setCurrPageSize(goodsList.size());
        pageBean.setPageSize(pageSize);
        pageBean.setTotalPages(page.getPages());
        pageBean.setTotalNums((int) page.getTotal());
        return pageBean;
    }

    @Override
    public List<Student> getStuByKid(Integer klassId) {
        return attendMapper.getStuByKid(klassId);
    }

    @Override
    public void updateAttendStatusBySid(Integer sid, String attendStatus) {
        attendMapper.updateAttendStatusBySid(sid,attendStatus);
    }

    @Override
    public void updateAttendStatusByKlassId(Integer klassId, String attendStatus) {
        attendMapper.updateAttendStatusByKlassId(klassId,attendStatus);
    }

    @Override
    public String getDateByDate(String date) {
        return attendMapper.getDateByDate(date);
    }


    @Override
    public void addRecord(Attend attend) {

        attendMapper.insert(attend);
    }

    @Override
    public void updateByCondition(Attend attend) {
        attendMapper.updateByCondition(attend);
    }

    @Override
    public Integer getAttendStatusNum(String attendStatus, Integer klassId) {
        return attendMapper.getAttendStatusNum(attendStatus,klassId);
    }
}
